﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Menu.aspx.cs" Inherits="WebApplication.Admin.Menu" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>菜单管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <style type="text/css">
        .mini-summary-row
        {
            background-color: #FFFFE6;
        }
        html, body
        {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div style="width: 100%;" runat="server" id="operationPanel">
        <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="addRow()" plain="true" tooltip="增加...">
                            增加</a><span class="separator"></span><a class="mini-button" iconcls="icon-remove"
                                onclick="deleteRows()" plain="true" tooltip="删除选中的菜单项（有子项的菜单项无法删除）">删除</a>
                    </td>
                    <td style="white-space: nowrap;">
                        <input id="key" class="mini-textbox" emptytext="请输入名称" style="width: 150px;" onenter="onKeyEnter" />
                        <a class="mini-button" onclick="search()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-treegrid" style="width: 100%; height: 100%;" allowresize="true"
            pagesize="20" allowcellselect="true" multiselect="true" allowcelledit="false"
            expandonload="true" oncellendedit="cellendedit" allowcellvalid="true" editnextonenterkey="true"
            editnextrowcell="true" url="/Handler.ashx?method=LoadMenu" treecolumn="text"
            resultastree="false" idfield="ID" onrowdblclick="onRowDblClick" parentfield="PID"
            emptytext="数据为空，<a href='javascript:newRow()'>增加一条</a>" showemptytext="true">
            <div property="columns">
                <div type="indexcolumn" headeralign="center" allowsort="true">
                    序号</div>
                <div type="checkcolumn">
                </div>
                <div name="text" field="Text" width="120" headeralign="center" allowsort="true" required="true"
                    vtype="required;maxLength:50">
                    名称
                    <input property="editor" class="mini-textbox" style="width: 100%;" />
                </div>
                <div type="checkboxcolumn" name="Visible" field="Visible" width="30" headeralign="center"
                    allowsort="true" required="true">
                    可见
                </div>
                <div field="iconCls" width="60" allowsort="true" vtype="maxLength:50">
                    图标类名
                    <input property="editor" class="mini-textbox" style="width: 100%;" />
                </div>
                <div field="Url" width="150" allowsort="true" vtype="maxLength:255">
                    URL
                    <input property="editor" class="mini-textbox" style="width: 100%;" />
                </div>
                <div name="edit" field="ProcessCategoryMappingID" width="80" align="center" headeralign="center">
                    操作
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.on("drawcell", function (e) {
            var column = e.column;
            //action列，超连接操作按钮
            if (column.name == "edit") {
                e.cellStyle = "text-align:center";
                e.cellHtml = '<a href="javascript:openEditPage(' + e.rowIndex + ')">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;';
                e.cellHtml += '<a href="javascript:deleteRow(' + e.rowIndex + ')">删除</a>';
            }
        });
        grid.load();

        function search() {
            var key = mini.get("key").getValue();

            grid.load({ key: key });
        }

        function onKeyEnter(e) {
            search();
        }

        function addRow() {
            var parentNode = grid.getSelectedNode();
            mini.open({
                url: "/admin/MenuForm.aspx?mode=add",
                title: "新增菜单项",
                width: 532,
                height: 243,
                onload: function () {
                    if (parentNode) {
                        var iframe = this.getIFrameEl();
                        iframe.contentWindow.SetParent(parentNode);
                    }
                },
                ondestroy: function (action) {
                    if (action == "changed") { grid.reload(); }
                }
            });
        }

        function deleteRow(rowIndex) {
            var array = new Array();
            array.push(grid.getRow(rowIndex).ID);
            delMenus(array);
        }
        function deleteRows() {
            var array = new Array();
            var datas = grid.getSelectedNodes();
            for (var i = 0; i < datas.length; i++) {
                array.push(datas[i].ID);
            }
            delMenus(array);
        }
        function delMenus(ids) {
            grid.loading("");
            $.ajax({
                url: "/Handler.ashx?method=DelMenu",
                data: { data: mini.encode(ids) },
                type: "post",
                success: function (text) {
                    var result = mini.decode(text);
                    if (result.Success) {
                        grid.reload();
                    } else {
                        grid.unmask(); mini.alert("保存失败：" + result.Message)
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert(jqXHR.responseText);
                    grid.unmask();
                }
            });
        }

        function openEditPage(rowIndex) {
            mini.open({
                url: "/admin/MenuForm.aspx?mode=edit&id=" + grid.getRow(rowIndex).ID,
                title: "编辑菜单项",
                width: 532,
                height: 243,
                ondestroy: function (action) {
                    if (action == "changed") { grid.reload(); }
                }
            });
        }
    </script>
</body>
</html>
